angular.module('CheckWork')


.directive('defectCheck', function() {
  return {
    restrict: 'E',
    scope: {
      value: '=',
      name: '=',
      pop: '&',
      push: '&'
    },
    template: '<div ng-click="process()" ng-model="value">{{name}}</div>',
    // link: function(scope) {
    //   // scope.selected = false;
    //   // scope.$on('clearRadio', function() {
    //   //   scope.selected = false;
    //   // });
    //   scope.process = function() {

    //     if (!scope.selected) {
    //       scope.push({
    //         'l': {
    //           value: scope.value,
    //           name: scope.name
    //         }
    //       });
    //       scope.selected = true;
    //     } else {
    //       scope.pop({
    //         'l': {
    //           value: scope.value,
    //           name: scope.name
    //         }
    //       });
    //       scope.selected = false;
    //     }
    //   };
    // },
    controller: ['$scope', function($scope) {
      $scope.process = function() {

        if (!$scope.selected) {
          $scope.push({
            'l': {
              value: $scope.value,
              name: $scope.name
            }
          });
          $scope.selected = true;
        } else {
          $scope.pop({
            'l': {
              value: $scope.value,
              name: $scope.name
            }
          });
          $scope.selected = false;
        }
      };
    }]
  };
});